package org.txazo.blog.web.action.base;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.txazo.blog.util.HttpUtil;

import com.opensymphony.xwork2.ActionSupport;

/**
 * JsonBaseAction
 * 
 * @author Tu XiaoZhou
 * @since 2013-08-12
 * 
 */
@ParentPackage("json-default")
@Namespace("/json")
@Results({ @Result(type = "json") })
public class JsonBaseAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	protected HttpServletRequest request = null;
	protected HttpServletResponse response = null;
	protected HttpSession session = null;
	protected ServletContext application = null;

	public JsonBaseAction() {
		super();

		init();
	}

	private void init() {
		request = ServletActionContext.getRequest();
		response = ServletActionContext.getResponse();
		session = request.getSession();
		application = session.getServletContext();
	}

	protected String getRemoteIP() {
		return HttpUtil.getRemoteIp(request);
	}

	protected HttpServletRequest getRequest() {
		return request;
	}

	protected HttpServletResponse getResponse() {
		return response;
	}

	protected HttpSession getSession() {
		return session;
	}

	protected ServletContext getApplication() {
		return application;
	}

}
